package com.wc.AlgoOJ_homework.ALgoOJ_BL5.I_蜂巢;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/4/10 21:06
 * @description http://43.138.190.70:8888/p/531?tid=66120c2c07c5c018a5dcf262
 */
public class Main {
    static Scanner sc = new Scanner(System.in);
    static int d1, p1, q1, d2, p2, q2;

    public static void main(String[] args) {
        d1 = sc.nextInt();
        p1 = sc.nextInt();
        q1 = sc.nextInt();
        d2 = sc.nextInt();
        p2 = sc.nextInt();
        q2 = sc.nextInt();
        double[] point1 = work(d1, p1, q1);
        double[] point2 = work(d2, p2, q2);
        System.out.println((long) getDis(point1, point2));
    }

    static double[] work(int d, int p, int q) {
        double x = 0, y = 0;
        if (d == 0) {
            x -= p;
            x += q * 0.5;
            y = q;
        } else if (d == 1) {
            x -= p * 0.5;
            x += q;
            y = p;
        } else if (d == 2) {
            x = (p + q) * 0.5;
            y = p - q;
        } else if (d == 3) {
            x += p;
            x -= q * 0.5;
            y -= q;
        } else if (d == 4) {
            x += p * 0.5;
            x -= q;
            y -= p;
        } else {
            x -= (p + q) * 0.5;
            y = q - p;
        }

        return new double[]{x, y};
    }

    static double getDis(double[] a, double[] b) {
        if (a[1] < b[1]) return getDis(b, a);
        if (a[0] == b[0]) {
            return b[1] - a[1];
        }
        double res = 0;
        // a在左上方
        if (a[0] < b[0]) {
            res += a[1] - b[1];
            a[0] += (a[1] - b[1]) * 0.5;
            // 如果超过了，可以在中间拐弯
            if (a[0] < b[0]) res += b[0] - a[0];
        } else {
            // a在右上方
            res += a[1] - b[1];
            a[0] -= (a[1] - b[1]) * 0.5;
            // 如果超过了，可以在中间拐弯
            if (a[0] > b[0]) res += a[0] - b[0];
        }
        return res;
    }
}
